package com.jinxi.algorithm.leetcode;

class MinLettle {

    public char nextGreatestLetter(char[] letters, char target) {
        char min = letters[0];
        int diff = Integer.MAX_VALUE;
        for(char v : letters){
            int di =  v - target;
            if(di <= 0 ){
                continue;
            }
            if(di < diff){
                diff = di ;
                min = v;
            }
        }
        return min;
    }

    public static void main(String[] args) {
        MinLettle lettle = new MinLettle();
//        char[] lettles = {'a','b'};
//        char target = 'z';
//        System.out.println(lettle.nextGreatestLetter(lettles,target));


        char[] l1 = {'c','f','j'};
        char target = 'a';
        System.out.println(lettle.nextGreatestLetter(l1,target));

        char[] l2 = {'c','f','j'};
        target = 'c';
        System.out.println(lettle.nextGreatestLetter(l2,target));


    }
}